﻿package mortal.game.resource.tableConfig
{
    import Message.DB.Tables.*;
    import com.gengine.resource.*;
    import flash.utils.*;
    import mortal.game.manager.*;
    import mortal.game.view.common.*;

    public class WorldBossConfig extends Object
    {
        private var _dic:Dictionary;
        private var _showAry:Array;
        private static var _instance:WorldBossConfig;

        public function WorldBossConfig()
        {
            this._dic = new Dictionary();
            this._showAry = new Array();
            if (_instance != null)
            {
                throw new Error("WorldBossConfig 单例");
            }
            this.init();
            return;
        }// end function

        public function init() : void
        {
            var _loc_1:* = ConfigManager.instance.getJSONByFileName("t_world_boss.json");
            this.write(_loc_1);
            _loc_1 = ConfigManager.instance.getJSONByFileName("t_world_boss_show.json");
            this.writeBossShow(_loc_1);
            return;
        }// end function

        private function write(param1:Object) : void
        {
            var _loc_2:TWorldBoss = null;
            var _loc_3:Object = null;
            for each (_loc_3 in param1)
            {
                
                _loc_2 = new TWorldBoss();
                ClassTypesUtil.copyValue(_loc_2, _loc_3);
                this._dic[_loc_2.bossCode] = _loc_2;
            }
            return;
        }// end function

        private function writeBossShow(param1:Object) : void
        {
            var _loc_2:TWorldBossShow = null;
            var _loc_3:Object = null;
            for each (_loc_3 in param1)
            {
                
                _loc_2 = new TWorldBossShow();
                ClassTypesUtil.copyValue(_loc_2, _loc_3);
                this._showAry.push(_loc_2);
            }
            return;
        }// end function

        public function getWorldBossByCode(param1:int) : TWorldBoss
        {
            return this._dic[param1];
        }// end function

        public function getWorldBossByMapId(param1:int) : TWorldBoss
        {
            var _loc_2:TWorldBoss = null;
            for each (_loc_2 in this._dic)
            {
                
                if (_loc_2.mapId == param1)
                {
                    return _loc_2;
                }
            }
            return null;
        }// end function

        public function getShowBossCodeList(param1:int, param2:int) : Array
        {
            var _loc_3:TWorldBossShow = null;
            for each (_loc_3 in this._showAry)
            {
                
                if (_loc_3.type == param2 && _loc_3.minLevel <= param1 && _loc_3.maxLevel >= param1)
                {
                    return _loc_3.bossCodeList.split("#");
                }
            }
            return [];
        }// end function

        public function getWorldBossShow(param1:int, param2:int) : Array
        {
            var _loc_6:int = 0;
            var _loc_7:TWorldBoss = null;
            var _loc_3:* = new Array();
            var _loc_4:* = this.getShowBossCodeList(param1, param2);
            var _loc_5:int = 0;
            while (_loc_5 < _loc_4.length)
            {
                
                _loc_6 = int(_loc_4[_loc_5]);
                if (this._dic[_loc_6])
                {
                    _loc_7 = this._dic[_loc_6] as TWorldBoss;
                    if (ClockManager.instance.serverOpenDateNum > 1 || _loc_7.type == 1 || param2 != 2)
                    {
                        _loc_3.push(_loc_7);
                    }
                }
                _loc_5++;
            }
            return _loc_3;
        }// end function

        public static function get instance() : WorldBossConfig
        {
            if (_instance == null)
            {
                _instance = new WorldBossConfig;
            }
            return _instance;
        }// end function

    }
}
